package 动态数组.队列;

import 动态数组.线性表.ArrayList;
import 动态数组.队列.接口.Queue;

import java.util.Iterator;

public class ArrayQueue<E> implements Queue<E> {

    private ArrayList<E> list;

    public ArrayQueue(){
        list = new ArrayList<>();
    }

    @Override
    public int size() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void offer(E element) {
        list.add(element);
    }

    @Override
    public E poll() {
        return list.remove(0);
    }

    @Override
    public E element() {
        return list.get(0);
    }

    @Override
    public void clear() {
        list.clear();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null){
            return false;
        }
        if (this == obj){
            return true;
        }
        if (getClass() != obj.getClass()){
            return false;
        }
        ArrayQueue other = (ArrayQueue) obj;
        return list.equals(other.list);
    }

    @Override
    public String toString() {
        return list.toString();
    }

    @Override
    public Iterator<E> iterator() {
        return list.iterator();
    }
}
